/*
 * Copyright 2010 J Patrick Davenport
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package v4view.web;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import v4view.web.ext.BindingSelect;

public class CoreAttributeBaseTests {
	private List<ICoreAttributes>	coreBearing;
	private ICoreAttributes			core;

	public CoreAttributeBaseTests() {
		this.coreBearing = new ArrayList<ICoreAttributes>();
		this.coreBearing.add(new A());
		this.coreBearing.add(new Body());
		this.coreBearing.add(new Br());
		this.coreBearing.add(new Form());
		this.coreBearing.add(new Image());
		this.coreBearing.add(new Li());
		this.coreBearing.add(new Link());
		this.coreBearing.add(new OptGroup());
		this.coreBearing.add(new Option());
		this.coreBearing.add(new Select());
		this.coreBearing.add(new Ul());
		this.coreBearing.add(new Caption());
		this.coreBearing.add(new Div());
		this.coreBearing.add(new P());
		this.coreBearing.add(new Span());
		this.coreBearing.add(new Table());
		this.coreBearing.add(new Tr());
		this.coreBearing.add(new TBody());
		this.coreBearing.add(new TFoot());
		this.coreBearing.add(new THead());
		this.coreBearing.add(new Td());
		this.coreBearing.add(new CheckBox());
		this.coreBearing.add(new File());
		this.coreBearing.add(new Hidden());
		this.coreBearing.add(new InputButton());
		this.coreBearing.add(new InputImage());
		this.coreBearing.add(new Reset());
		this.coreBearing.add(new Submit());
		this.coreBearing.add(new Text());
		this.coreBearing.add(new BindingSelect());
		this.coreBearing.add(new Script());
		this.coreBearing.add(new HtmlObject());
	}

	@Test
	public void runAttributeTests() throws Exception {
		for (final ICoreAttributes c : this.coreBearing) {
			try {
				this.core = c;
				this.checkGetSetId();
				this.checkGetSetStyle();
				this.checkGetSetTitle();
				this.checkSetGetCssClass();
			} catch (final Exception ex) {
				System.err.println("Failed for type: " + c.getClass());
				throw ex;
			}
		}
	}

	public void checkGetSetTitle() {
		final String title = "A good title";
		this.core.setTitle(title);
		assertEquals(title, this.core.getTitle());

		final String newTitle = "a better title";
		this.core.setTitle(newTitle);
		assertEquals(newTitle, this.core.getTitle());
	}

	public void checkGetSetStyle() {
		final String style = "border: solid 1px black;";
		this.core.setStyle(style);
		assertEquals(style, this.core.getStyle());

		final String newStyle = "float: left";
		this.core.setStyle(newStyle);
		assertEquals(newStyle, this.core.getStyle());
	}

	public void checkGetSetId() {
		final String id = "myId";
		this.core.setId(id);
		assertEquals(id, this.core.getId());

		final String anotherId = "aNewId";
		this.core.setId(anotherId);
		assertEquals(anotherId, this.core.getId());
	}

	public void checkSetGetCssClass() {
		final String value = "testClass";
		this.core.setCssClass(value);
		assertEquals(value, this.core.getCssClass());

		final String multiClasses = "class1 class2";
		this.core.setCssClass(multiClasses);
		assertEquals(multiClasses, this.core.getCssClass());
	}
}
